//
//  GluNetObj.h
//  CareRingApp
//
//  Created  on 2025/2/14.
//
    

#import <Foundation/Foundation.h>

// keys
#define GLU_FASTING     @"fasting" // 空腹8小时
#define GLU_WITHIN_2_HOR    @"within2HrsMeal" // 是否在餐后2小时之内
#define GLU_STAET       @"start"
#define GLU_END         @"end"
#define GLU_PPGDATA     @"ppgData"

#define GLU_PPG         @"ppg"
#define GLU_TIMESTAMP   @"timestamp"



NS_ASSUME_NONNULL_BEGIN

@class GluPPGSubObj;

@interface GluNetObj : NSObject

@property(assign, nonatomic)BOOL fasting, within2HrsMeal;
@property(strong, nonatomic)NSDate *start, *end;
@property(strong, nonatomic)NSMutableArray<GluPPGSubObj *> *ppgData;
@property(assign, nonatomic)NSUInteger maxCount;

@property(assign, nonatomic)NSInteger currentCount;

@property(assign, nonatomic, readonly)BOOL isEnough;

@property(strong, nonatomic, readonly)NSString *mid;

-(CGFloat)progressPercentValue; // 百分比 0-1

// 打包成请求的格式
-(NSMutableDictionary *)packToReqDict;
/// 收集ppg数据,return yes = 收集满了
/// - Parameter newPpgs: ppg数据
-(BOOL)addPPg:(NSMutableArray<NSNumber *> *)newPPgs;

/// 登记设备序列号
/// - Parameters:
///   - host: 地址
///   - sn: 设备 sn
///   - age: 年龄
///   - isMale: 是否 男性
///   - weight: 体重 KG
///   - height: 身高 CM
///   - familyHistory: 是/否有糖尿病家庭病史
///   - highCholesterol: 是/否有⾼胆固醇病史
///   - ur: 1/0在sn已存如⽆该参数则默认不更新在的情况下，再次调⽤本接⼝是否更新上游数据
///   - handler: 回调
///   - servernil: 回调
+(void)gluRegPsn:(NSString *)host
              SN:(NSString *)sn
             Age:(NSUInteger)age
          Gender:(BOOL)isMale
          Weight:(NSUInteger)weight
          Height:(NSUInteger)height
   FamilyHistory:(BOOL)familyHistory
 HighCholesterol:(BOOL)highCholesterol
             Key:(NSString *)key
             MacAddr:(NSString *)mac
          Secret:(NSString *)secret
            AndComplated:(void (^)(NSHTTPURLResponse * _Nullable httpResp,  NSDictionary * _Nullable content,  NSNumber * _Nullable state , NSNumber * _Nullable lease, NSString *ltk)) handler
            AndServerNil:(void (^)(void))servernil;


-(void)gluNewSmp:(NSString *)host
       DataArray:(NSDictionary *)postDict
             Ltk:(NSString *)ltk
              SN:(NSString *)sn
             Key:(NSString *)key
             MacAddr:(NSString *)mac
          Secret:(NSString *)secret
            AndComplated:(void (^)(NSHTTPURLResponse * _Nullable httpResp,  NSDictionary * _Nullable content, NSNumber *  _Nullable state)) handler
            AndServerNil:(void (^)(void))servernil;


/// 获取ppg算法结果, gluNewSmp调用后 5s以后调用
/// - Parameters:
///   - host: 域名
///   - mid: gluNewSmp 返回的结果
///   - sn: 设备sn
///   - handler: 回调
///   - servernil: 回调
-(void)gluAnrSmp:(NSString *)host
             Mid:(NSString *)mid
              SN:(NSString *)sn
             Key:(NSString *)key
             MacAddr:(NSString *)mac
          Secret:(NSString *)secret
            AndComplated:(void (^)(NSHTTPURLResponse * _Nullable httpResp,  NSDictionary * _Nullable content, NSNumber *  _Nullable state)) handler
    AndServerNil:(void (^)(void))servernil;

@end



@interface GluPPGSubObj : NSObject

@property(strong, nonatomic)NSDate *date;
@property(strong, nonatomic)NSMutableArray<NSNumber *> *ppgArray;

-(NSMutableDictionary *)packDict;


@end

NS_ASSUME_NONNULL_END
